/*
 *                        _oo0oo_
 *                       o8888888o
 *                       88" . "88
 *                       (| -_- |)
 *                       0\  =  /0
 *                     ___/`---'\___
 *                   .' \\|     |// '.
 *                  / \\|||  :  |||// \
 *                 / _||||| -:- |||||- \
 *                |   | \\\  - /// |   |
 *                | \_|  ''\---/''  |_/ |
 *                \  .-\__  '-'  ___/-. /
 *              ___'. .'  /--.--\  `. .'___
 *           ."" '<  `.___\_<|>_/___.' >' "".
 *          | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *          \  \ `_.   \_ __\ /__ _/   .-` /  /
 *      =====`-.____`.___ \_____/___.-`___.-'=====
 *                        `=---='
 * 
 * 
 *      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 
 *            佛祖保佑     永不宕机     永无BUG
 * 
 *        佛曰:  
 *                写字楼里写字间，写字间里程序员；  
 *                程序人员写程序，又拿程序换酒钱。  
 *                酒醒只在网上坐，酒醉还来网下眠；  
 *                酒醉酒醒日复日，网上网下年复年。  
 *                但愿老死电脑间，不愿鞠躬老板前；  
 *                奔驰宝马贵者趣，公交自行程序员。  
 *                别人笑我忒疯癫，我笑自己命太贱；  
 *                不见满街漂亮妹，哪个归得程序员？
 */



#include "tim.h"
#include "usart.h"
 
#include "general_task_include.h"



TaskHandle_t decisionTaskHandle;
TaskHandle_t stateMachineTaskHandle;
TaskHandle_t controlTaskHandle;
TaskHandle_t upperPCCommTaskHandle;
TaskHandle_t remoteRecTaskHandle;
TaskHandle_t uiOperationTaskHandle;
TaskHandle_t monitorTaskHandle;
TaskHandle_t imuTaskHandle;
TaskHandle_t debugTaskHandle;
/*外设及freertos相关初始化所需的其他源文件中的全局变量*/
void InitialTask(void const * argument)
{
	taskENTER_CRITICAL();
	/**PWM for LED**/
	HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_1);
	HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_2);
	HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_3);
	/** PWM for IMU heating **/
	HAL_TIM_PWM_Start(&htim10,TIM_CHANNEL_1);               	
	__HAL_TIM_SET_COMPARE(&htim10, TIM_CHANNEL_1,HEAT_MAX);
	
	PeripheralRecEnable();

	//外设初始化完成提示·
	HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3);
	__HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3,500);
	

	xTaskCreate(RemoteRecTask,      "RemoteRecTask_",    	256,  NULL,  7,  &remoteRecTaskHandle    );	
	xTaskCreate(StateMachineTask,   "StateMachineTask_",  	128,  NULL,  5,  &stateMachineTaskHandle );	
	xTaskCreate(DecisionTask, 	    "DecisionTask_", 	    256,  NULL,  4,  &decisionTaskHandle     );
	xTaskCreate(ControlTask,        "ControlTask_",       	256,  NULL,  6,  &controlTaskHandle      );




	
	//HAL_Delay(200);    
	__HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3,0);	
	vTaskDelete(NULL);          
	taskEXIT_CRITICAL();   
}




